﻿using System;
using System.Collections.Generic;
using System.Text;
using AMS.Configuration;

namespace AMS.UI.Controls
{
    /// <summary>
    /// 
    /// </summary>
    public static class DictControlUtils
    {
        /// <summary>
        /// 生成如同 key - value 的格式
        /// </summary>
        /// <param name="key"></param>
        /// <param name="subKey"></param>
        /// <returns></returns>
        public static string GetDictText(int key, string subKey)
        {
            string value = Dict.Instance.GetDictValue(key, subKey);
            if (string.IsNullOrEmpty(value))
            {
                return null;
            }
            else
            {
                return string.Format("{0} - {1}", key, value);
            }
        }

        /// <summary>
        /// 从 key - value 中解析出 key
        /// </summary>
        /// <param name="text"></param>
        /// <returns></returns>
        public static string ExtractKeyFromText(string text)
        {
            if (string.IsNullOrEmpty(text))
            {
                return string.Empty;
            }

            int index = text.IndexOf('-');
            if (index <= 0)
            {
                return string.Empty;
            }

            return text.Substring(0, index).Trim();
        }

        /// <summary>
        /// 从key - value中解析出value
        /// </summary>
        /// <param name="text"></param>
        /// <returns></returns>
        public static string ExtractValueFromText(string text)
        {
            if (string.IsNullOrEmpty(text))
            {
                return string.Empty;
            }

            int index = text.IndexOf('-');
            if (index < 0)
            {
                return text;
            }

            return text.Remove(0, index + 1).Trim();
        }
    }
}
